package vn.com.tiz.DocumentZ.task;

import java.io.IOException;
import java.io.StringReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Xml;

public abstract class Supporter {
	protected int appId;
	protected int resultCode = -1;
	protected String errCode = null;
	
	public Supporter(int argAppId) {
		appId = argAppId;
	}

	protected boolean parse(String xml) {
		try {
			XmlPullParser xpp = Xml.newPullParser();
			xpp.setInput(new StringReader(xml));
			while (xpp.getEventType() != XmlPullParser.END_DOCUMENT) {
				if (xpp.getEventType() == XmlPullParser.START_TAG) {
					if (xpp.getName().equals("Result")) {
						resultCode = Integer.valueOf(xpp.nextText());
					} else if (xpp.getName().equals("Error")) {
						errCode = xpp.nextText();
					} else if (isUse(xpp.getName())) {
						putValue(xpp.getName(), xpp.nextText());
					}
				}
				xpp.next();
			}
			if (resultCode < 0) {
				return false;
			}
			return true;
		} catch (XmlPullParserException e) {
		} catch (NumberFormatException e) {
		} catch (IOException e) {
		}
		return false;
	}
	
	protected abstract boolean isUse(String tag);
	protected abstract void putValue(String tag, String value);
}